from flask import Flask, request, jsonify, Response, send_from_directory, send_file
from flask_cors import CORS

import os
import json

app = Flask(__name__)
CORS(app,  resources={r"/*": {"origins": "*"}})



@app.route("/api/mgw1/upload", methods=['POST', 'GET'])
def upload():
    file = request.files['file']
    upload_path = os.path.join("file/test." + file.filename.split(".")[-1])
    file.save(upload_path)
    return Response(json.dumps({
        'code': 0
    }), mimetype='application/json')


@app.route("/api/mgw1/download")
def j2_tab3_down():
    filename = 'test.pdf'
    return send_file(os.path.join("./file/") + filename, as_attachment=True)



if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000, debug=True)
